Import diddy
Import globals
Import hamsimplemenu

Class TitleScreen Extends Screen
	Field menu:SimpleMenu
	Field musicFormat:String
	Field backgroundImage:Image
	
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "Forest.png")
	End
	
	Method Start:Void()

		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		Local b:SimpleButton = menu.AddButton("newgame.png", "newgameMO.png")
		b = menu.AddButton("continue.png", "continueMO.png")
		b = menu.AddButton("options.png", "optionsMO.png")
		b = menu.AddButton("quit.png", "quitMO.png")
		musicFormat="ogg"
		diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,120,320,240)
		SetColor(255,255,255)
		SetAlpha(1)		
		'DrawText "OHRPPGCE 2", SCREEN_WIDTH2, 10, 0.5, 0.5
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If menu.Clicked("newgame") Then
			FadeToScreen(mainedscreen)
		End
		
		If menu.Clicked("options") Then
			FadeToScreen(optionScreen)
		End
		
		If menu.Clicked("continue") Then
			FadeToScreen(mainedscreen)
		End
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(diddyGame.exitScreen)
		End
	End
End


Class MapTileMenuScreen Extends Screen
	Field menu:SimpleMenu
	Field tset:int
	'Field musicFormat:String
	Field backgroundImage:Image
	
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "Chaos.png")
	End
	
	Method Start:Void()

		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		'Local b:SimpleButton = menu.AddButton("newgame.png", "newgameMO.png")
		'b = menu.AddButton("continue.png", "continueMO.png")
		'b = menu.AddButton("options.png", "optionsMO.png")
		'b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(64,120,512,320)
		SetColor(255,255,255)
		SetAlpha(1)		
		Local mx:Int = diddyGame.mouseX
		Local my:Int = diddyGame.mouseY
		If Not diddyGame.virtualResOn
			mx = MouseX()
			my = MouseY()
		End
		For Local yy:Int = 0 To 9
			For Local xx:Int = 0 To 15
			
				DrawImage(TileSets[tset].image.image,80+(32*xx),136+(32*yy),xx+(yy*16))
				If mx >= 64+(32*xx) And mx < 64+(32*xx)+32 And my >= 120+(32*yy) And my < 120+(32*yy)+32 Then
					SetAlpha(0.5)
					DrawRect(64+(32*xx),120+(32*yy),32,32)
					If MouseDown( MOUSE_LEFT )
						'spriteeditor = New SpriteEd(32,32,tset,xx+(yy*16),TileSets[tset].simage,False,4,0,"Maptile: "+(xx+(yy*16)),Screen(maptmenu))'( 20, 20, 1, 8, 5, Info,  4, s, WalkaboutSpr[i])
						spriteeditor = New SpriteEd(32,32,xx+(yy*16),TileSets[tset].edsprites,False,4,0,"Maptile: "+(xx+(yy*16)),True,tset,Screen(maptmenu))
						FadeToScreen(spriteeditor)
					Endif	
					SetAlpha(1)
				Endif
			Next
		Next
		
		'DrawText "OHRPPGCE 2", SCREEN_WIDTH2, 10, 0.5, 0.5
	End
	
	Method ExtraRender:Void()
		menu.Draw()
		
	End
	
	Method Update:Void()
		menu.Update()
		
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(maptiles)
		End
	End
End

Class MaptilesScreen Extends Screen
	Field menu:HamSimpleMenu[]
	Field musicFormat:String
	Field backgroundImage:Image
	Field Info:String[]
	Field CurrentInfo:Int
	Method New()
		name = "Maptiles"
		backgroundImage = LoadImage(diddyGame.images.path + "Chaos.png")
	End
	
	Method Start:Void()
		Local b:HamSimpleButton
		Local m:HamSimpleMenu[TileSets.Length]
		Local ifo:String[TileSets.Length]
		'need to setup default sprites for this...
		For Local i:Int = 0 To TileSets.Length-1
			m[i] = New HamSimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False,HORIZONTAL)	
			
			b = m[i].AddHButton(TileSets[i].image, TileSets[i].image,"Menu_"+i)
			ifo[i] = TileSets[i].name
			m[i].SetX((SCREEN_WIDTH-m[i].CalcWidth())/2)
			m[i].SetY(TileSets[i].image.image.Height()+120+((TileSets[i].image.image.Height()+10)*i))
		Next
		Info = ifo
		menu = m
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")		
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")		
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")		
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
		
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		
	End
	
	Method Render:Void()
		
		
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,120,320,240)
		SetColor(255,255,255)
		SetAlpha(1)		
		MainFont.DrawHTML(Info[CurrentInfo], SCREEN_WIDTH-128,20)
		'DrawText "OHRPPGCE 2", SCREEN_WIDTH2, 10, 0.5, 0.5
	End
	
	Method ExtraRender:Void()
		For Local i:Int = 0 To menu.Length-1
			menu[i].Draw()
		Next
	End
	
	Method Update:Void()
		'Local info:String[] = ["Up A","Up B","Right A","Right B","Down A","Down B","Left A","Left B"]
		For Local i:Int = 0 To menu.Length-1
			menu[i].Update()
			
		
				If menu[i].mouseOverName = String("Menu_"+i).ToUpper Then
					CurrentInfo = i
				end
				If menu[i].Clicked("Menu_"+i) Then
				
					maptmenu = New MapTileMenuScreen
					maptmenu.tset = i
					FadeToScreen(maptmenu)
				
					'If spriteeditor = Null Then
						
					'	spriteeditor = New SpriteEd(20,20,s,WalkaboutSpr[i],False,4,0,info[s])'( 20, 20, 1, 8, 5, Info,  4, s, WalkaboutSpr[i])
					'Else
						
					'Endif
					'FadeToScreen(spriteeditor)
				End
				
				

			 
		Next
		If KeyHit(KEY_ESCAPE)
			FadeToScreen(gfxscreen)
		End		
	End
End


Class WalkaboutScreen Extends Screen
	Field menu:HamSimpleMenu[]
	Field musicFormat:String
	Field backgroundImage:Image
	Field Info:String[] = ["Up A","Up B","Right A","Right B","Down A","Down B","Left A","Left B"]
	Field CurrentInfo:Int
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "TownExt.png")
	End
	
	Method Start:Void()
		Local b:HamSimpleButton
		Local m:HamSimpleMenu[WalkaboutSpr.Length]
		'need to setup default sprites for this...
		For Local i:Int = 0 To WalkaboutSpr.Length-1
			m[i] = New HamSimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False,HORIZONTAL)	
			For Local s:Int = 0 To 	WalkaboutSpr[i].frames.Length-1
				b = m[i].AddHButton(WalkaboutSpr[i].frames[s].image, WalkaboutSpr[i].frames[s].image,"Menu_"+i+"_"+s)
			Next
			m[i].SetX((SCREEN_WIDTH-m[i].CalcWidth())/2)
			m[i].SetY(WalkaboutSpr[i].frames[0].image.image.Height()+90+((WalkaboutSpr[i].frames[0].image.image.Height()+10)*i))
		Next
		menu = m
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")		
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")		
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")		
			'b = menu.AddButton("tmpspr.png", "tmpspr.png")
		
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		
	End
	
	Method Render:Void()
		
		
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(96,100,448,380)
		SetColor(255,255,255)
		SetAlpha(1)	
		MainFont.DrawHTML(Info[CurrentInfo], SCREEN_WIDTH-128,20)
		'DrawText "OHRPPGCE 2", SCREEN_WIDTH2, 10, 0.5, 0.5
	End
	
	Method ExtraRender:Void()
		For Local i:Int = 0 To menu.Length-1
			menu[i].Draw()
		Next
	End
	
	Method Update:Void()
		Local info:String[] = ["Up A","Up B","Right A","Right B","Down A","Down B","Left A","Left B"]
		For Local i:Int = 0 To menu.Length-1
			menu[i].Update()
			For Local s:Int = 0 To 	WalkaboutSpr[i].frames.Length-1
		
				If menu[i].mouseOverName = String("Menu_"+i+"_"+s).ToUpper Then
					CurrentInfo = s
				end
				If menu[i].Clicked("Menu_"+i+"_"+s) Then
					'If spriteeditor = Null Then
						
						spriteeditor = New SpriteEd(20,20,s,WalkaboutSpr[i],False,4,0,info[s],False,0,walkabout)'( 20, 20, 1, 8, 5, Info,  4, s, WalkaboutSpr[i])
					'Else
						
					'Endif
					FadeToScreen(spriteeditor)
				End
				
				

			Next 
		Next
		If KeyHit(KEY_ESCAPE)
			FadeToScreen(heronenemy)
		End		
	End
End

Class HeronEnemyScreen Extends Screen
	Field menu:SimpleMenu
	Field musicFormat:String
	Field backgroundImage:Image
	
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "Wasteland.png")
	End
	
	Method Start:Void()

		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		Local b:SimpleButton = menu.AddButton("walkabout.png", "walkaboutMO.png")
		b = menu.AddButton("hero.png", "heroMO.png")
		b = menu.AddButton("enemy.png", "enemyMO.png")		
		b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,120,320,240)
		SetColor(255,255,255)
		SetAlpha(1)	
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If menu.Clicked("walkabout") Then
			FadeToScreen(walkabout)
		End
		
		If menu.Clicked("hero") Then
			FadeToScreen(gfxscreen)
		End
		
		If menu.Clicked("enemy") Then
			FadeToScreen(gfxscreen)
		End
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(gfxscreen)
		End
	End
End


Class MapMenuScreen Extends Screen
	Field menu:HamSimpleTextMenu
	Field musicFormat:String
	Field backgroundImage:Image
	Field mapnum:int
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "FireCave.png")
	End
	
	Method Start:Void()

		menu = New HamSimpleTextMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		
		Local b:HamSimpleTextButton = menu.AddHTButton("Map Properties", "properties")
		b = menu.AddHTButton("Map Size", "resize")
		b = menu.AddHTButton("Edit Tiles", "tiled")
		b = menu.AddHTButton("Edit Walls", "walled")
		b = menu.AddHTButton("Edit NPCs", "npced")
		b = menu.AddHTButton("Edit Doors", "doored")
		b = menu.AddHTButton("Edit Foe-map", "foeed")
		b = menu.AddHTButton("Exit", "quit")
		
		'b = menu.AddButton("heroandenemy.png", "heroandenemyMO.png")
	
		'b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,100,320,320)
		SetColor(255,255,255)
		SetAlpha(1)	
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()

		If menu.Clicked("tiled") Then
			mapeditor = New MapEditorScreen(mapnum)
			FadeToScreen(mapeditor)
		End
		

		
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(datas)
		End
	End
End


Class MapScreen Extends Screen
	Field menu:HamSimpleTextMenu
	Field musicFormat:String
	Field backgroundImage:Image
	
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "FireCave.png")
	End
	
	Method Start:Void()

		menu = New HamSimpleTextMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		For Local i = 0 To Tilemaps.Length-1
			Local b:HamSimpleTextButton = menu.AddHTButton(Tilemaps[i].tname, "map_"+i)
		next
		'b = menu.AddButton("heroandenemy.png", "heroandenemyMO.png")
	
		'b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,100,320,260)
		SetColor(255,255,255)
		SetAlpha(1)	
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		For Local i = 0 To Tilemaps.Length-1
			If menu.Clicked("map_"+i) Then
				mapmenu = New MapMenuScreen
				mapmenu.mapnum = i
				FadeToScreen(mapmenu)
			End
		next		

		
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(datas)
		End
	End
End

Class DataScreen Extends Screen
	Field menu:SimpleMenu
	Field musicFormat:String
	Field backgroundImage:Image
	
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "FireTemple.png")
	End
	
	Method Start:Void()

		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		Local b:SimpleButton = menu.AddButton("maps.png", "mapsMO.png")
		'b = menu.AddButton("heroandenemy.png", "heroandenemyMO.png")
	
		b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,100,320,260)
		SetColor(255,255,255)
		SetAlpha(1)	
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If menu.Clicked("maps") Then
			mapsscreen = New MapScreen
			FadeToScreen(mapsscreen)
		End
		
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(mainedscreen)
		End
	End
End



Class GraphicsScreen Extends Screen
	Field menu:SimpleMenu
	Field musicFormat:String
	Field backgroundImage:Image
	
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "WaterTemple.png")
	End
	
	Method Start:Void()

		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		Local b:SimpleButton = menu.AddButton("maptiles.png", "maptilesMO.png")
		b = menu.AddButton("heroandenemy.png", "heroandenemyMO.png")
		b = menu.AddButton("battle.png", "battleMO.png")
		b = menu.AddButton("portrait.png", "portraitMO.png")		
		b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,100,320,260)
		SetColor(255,255,255)
		SetAlpha(1)	
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If menu.Clicked("maptiles") Then
			FadeToScreen(maptiles)
		End
		
		If menu.Clicked("heroandenemy") Then
			FadeToScreen(heronenemy)
		End
		
		If menu.Clicked("battle") Then
			FadeToScreen(mainedscreen)
		End

		If menu.Clicked("portrait") Then
			FadeToScreen(mainedscreen)
		End
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(mainedscreen)
		End
	End
End


Class MainEditorScreen Extends Screen
	Field menu:SimpleMenu
	Field musicFormat:String
	Field backgroundImage:Image
	Method New()
		name = "title"
		backgroundImage = LoadImage(diddyGame.images.path + "FireCave2.png")
	End
	
	Method Start:Void()
		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, False)
		Local b:SimpleButton = menu.AddButton("graphics.png", "graphicsMO.png")
		b = menu.AddButton("data.png", "dataMO.png")
		b = menu.AddButton("audio.png", "audioMO.png")
		b = menu.AddButton("quit.png", "quitMO.png")
		'musicFormat="ogg"
		'diddyGame.MusicPlay("day1."+musicFormat, True)
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawImage backgroundImage, 0, 0
		DrawImage MainLogo,160,32
		SetColor(0,0,0)
		SetAlpha(0.5)
		DrawRect(160,120,320,240)
		SetColor(255,255,255)
		SetAlpha(1)	
	End
	
	Method ExtraRender:Void()
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If menu.Clicked("graphics") Then
			FadeToScreen(gfxscreen)
		End
		
		If menu.Clicked("data") Then
			FadeToScreen(datas)
		End
		
		If menu.Clicked("audio") Then
			FadeToScreen(titleScreen)
		End
		
		If KeyHit(KEY_ESCAPE) Or menu.Clicked("quit")
			FadeToScreen(titleScreen)'diddyGame.exitScreen)
		End
	End
End


Class GameScreen Extends Screen
	Field menu:SimpleMenu
	
	Method Start:Void()
		diddyGame.screenFade.Start(50, False)
		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, True)
		Local b:SimpleButton = menu.AddButton("quit.png", "quitMO.png")
		menu.Centre()
	End
	
	Method Render:Void()
		Cls
		DrawText "GAME SCREEN", SCREEN_WIDTH2, 10, 0.5, 0.5
		menu.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If menu.Clicked("quit") Then
			FadeToScreen(titleScreen)
		End
	End
End

Class OptionScreen Extends Screen
	Field menu:SimpleMenu
	Field musicSlider:SimpleSlider
	
	Method Start:Void()
		diddyGame.screenFade.Start(50, False)
		menu = New SimpleMenu("ButtonOver", "ButtonClick", 0, 0, 10, True)
		Local b:SimpleButton = menu.AddButton("quit.png", "quitMO.png")
		menu.Centre()
		
		musicSlider = New SimpleSlider("slider_bar.png", "slider.png", SCREEN_WIDTH2 - 93, 115, 35, "music", 20, True)
		musicSlider.SetValue(diddyGame.musicVolume)
	End
	
	Method Render:Void()
		Cls
		DrawText "OPTION SCREEN", SCREEN_WIDTH2, 10, 0.5, 0.5
		menu.Draw()
		DrawText "MUSIC VOLUME:", musicSlider.x + (musicSlider.image.w / 2)  , musicSlider.y - 20, 0.5
		musicSlider.Draw()
	End
	
	Method Update:Void()
		menu.Update()
		
		If musicSlider.Update() Then
			diddyGame.MusicSetVolume(musicSlider.value)
		End If
		
		If menu.Clicked("quit") Then
			FadeToScreen(titleScreen)
		End
	End
End